#ifndef _GL_BLEND_H_
#define _GL_BLEND_H_

#include "..\glew\glew.h"

#include "..\cuCommon\cuTypes.h"

typedef enum GL_BLEND_OP
{
    GL_BLEND_OP_ADD             = GL_FUNC_ADD,
    GL_BLEND_OP_SUBTRACT        = GL_FUNC_SUBTRACT,
    GL_BLEND_OP_REV_SUBTRACT    = GL_FUNC_REVERSE_SUBTRACT,
    GL_BLEND_OP_MIN             = GL_MIN,
    GL_BLEND_OP_MAX             = GL_MAX,
} GL_BLEND_OP;

typedef enum GL_BLEND_FUNC
{
    GL_BLEND_ZERO               = GL_ZERO,
    GL_BLEND_ONE                = GL_ONE,
    GL_BLEND_SRC_COLOR          = GL_SRC_COLOR,
    GL_BLEND_INV_SRC_COLOR      = GL_ONE_MINUS_SRC_COLOR,
    GL_BLEND_SRC_ALPHA_FUNC     = GL_SRC_ALPHA,
    GL_BLEND_INV_SRC_ALPHA      = GL_ONE_MINUS_SRC_ALPHA,
    GL_BLEND_DEST_ALPHA         = GL_DST_ALPHA,
    GL_BLEND_INV_DEST_ALPHA     = GL_ONE_MINUS_DST_ALPHA,
    GL_BLEND_DEST_COLOR         = GL_DST_COLOR,
    GL_BLEND_INV_DEST_COLOR     = GL_ONE_MINUS_DST_COLOR,
    GL_BLEND_SRC_ALPHA_SAT      = GL_SRC_ALPHA_SATURATE,
    GL_BLEND_BLEND_FACTOR       = GL_CONSTANT_COLOR_EXT,
    GL_BLEND_INV_BLEND_FACTOR   = GL_ONE_MINUS_CONSTANT_COLOR_EXT,
    GL_BLEND_SRC1_COLOR         = GL_SRC1_RGB,
    //GL_BLEND_INV_SRC1_COLOR     = N/A,
    GL_BLEND_SRC1_ALPHA         = GL_SRC1_ALPHA,
    //GL_BLEND_INV_SRC1_ALPHA     = N/A,
} GL_BLEND_FUNC;

typedef enum GL_COLOR_WRITE_ENABLE
{
    GL_COLOR_WRITE_ENABLE_RED   = 1,
    GL_COLOR_WRITE_ENABLE_GREEN = 2,
    GL_COLOR_WRITE_ENABLE_BLUE  = 4,
    GL_COLOR_WRITE_ENABLE_ALPHA = 8,
    GL_COLOR_WRITE_ENABLE_ALL = (GL_COLOR_WRITE_ENABLE_RED | GL_COLOR_WRITE_ENABLE_GREEN |  
    GL_COLOR_WRITE_ENABLE_BLUE | GL_COLOR_WRITE_ENABLE_ALPHA ),

} GL_COLOR_WRITE_ENABLE;

typedef struct GL_BLEND_DESC 
{
    bool AlphaToCoverageEnable;
    bool BlendEnable[8];
    GLenum SrcBlend;
    GLenum DstBlend;
    GLenum BlendOp;
    GLenum SrcBlendAlpha;
    GLenum DstBlendAlpha;
    GLenum BlendOpAlpha;
    uint8 RenderTargetWriteMask[8];

    GL_BLEND_DESC()
    {
        AlphaToCoverageEnable = false;

        BlendEnable[0] = 
        BlendEnable[1] = 
        BlendEnable[2] = 
        BlendEnable[3] = 
        BlendEnable[4] = 
        BlendEnable[5] = 
        BlendEnable[6] = 
        BlendEnable[7] = GL_FALSE;

        RenderTargetWriteMask[0] = GL_COLOR_WRITE_ENABLE_ALL;
        RenderTargetWriteMask[1] = 
        RenderTargetWriteMask[2] = 
        RenderTargetWriteMask[3] = 
        RenderTargetWriteMask[4] = 
        RenderTargetWriteMask[5] = 
        RenderTargetWriteMask[6] = 
        RenderTargetWriteMask[7] = GL_FALSE;

        SrcBlend      = GL_BLEND_ONE;
        DstBlend      = GL_BLEND_ZERO;    
        SrcBlendAlpha = GL_BLEND_ONE;
        DstBlendAlpha = GL_BLEND_ZERO;

        BlendOp      = GL_BLEND_OP_ADD;
        BlendOpAlpha = GL_BLEND_OP_ADD;
    }
} GL_BLEND_DESC;



void glSetBlendState(const GL_BLEND_DESC *pDesc, const float BlendFactor[4]);

#endif